package service;

import java.util.ArrayList;
import java.util.Iterator;
import Pet.Pet;
import way.Way;
public class Service {
	private Way way=new Way();
	public ArrayList<Pet> queryPet(){
		ArrayList<Pet> data=way.queryAllData();
		return data;
	}
	public boolean addPet(String no,String type,String age,String number,String price){
		ArrayList<Pet> data=queryPet();
		Iterator<Pet> iterator=data.iterator(); 
		while(iterator.hasNext()){
			Pet pet=iterator.next();
			if(pet.getNo().equals(no)){
				return false;
			}
		}
		Pet thisPet=new Pet(no,type,age,number,price);
		way.addPet(thisPet);
		return true;
	}
	public boolean updatePet(String no,String type,String age,String number,String price){
		ArrayList<Pet> data=queryPet();
		for(int i=0;i<data.size();i++){
			Pet pet=data.get(i);
			if(pet.getNo().equals(no)){
				way.delPet(no);
				Pet thisPet=new Pet(no,type,age,number,price);
				way.addPet(thisPet);;
				return true;
			}
		}
		return false;
	}
	public boolean delPet(String no){
		ArrayList<Pet> data=queryPet();
		for(int i=0;i<data.size();i++){
			Pet pet=data.get(i);
			if(pet.getNo().equals(no)){
				way.delPet(no);
				return true;
			}
		}
		return false;
	}
	

}




